/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxinline.servico;

import br.com.foxinline.modelo.Setor;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.Query;

/**
 *
 * @author laverson
 */
@Stateless
public class SetorServico extends ServicoGenerico<Setor> {

    public SetorServico() {
        super(Setor.class);
    }
    
     public List<Setor> pesquisarSetor(Setor setor) {
        String sql = "SELECT s FROM Setor s ";
        sql += " where ";
        if ((setor.getNome() != null) && !setor.getNome().equals("")) {
            sql += " lower(s.nome) like lower(:nome) and ";
        }
        sql += " s.ativo = TRUE AND 1=1 ";
        System.err.print(sql);
        Query query = getEntityManager().createQuery(sql);

        if ((setor.getNome() != null) && !setor.getNome().equals("")) {
            query.setParameter("nome", "%"+setor.getNome()+"%");
        }
        return (List<Setor>) query.getResultList();
    }

      public boolean setorObrigatorio(Setor setor) {
        return !setor.getNome().equals("");
    }
    
}
